package com.cpems.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.cpems.system.domain.SysEnergyProject;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.cpems.common.annotation.RepeatSubmit;
import com.cpems.common.annotation.Log;
import com.cpems.common.core.controller.BaseController;
import com.cpems.common.core.domain.PageQuery;
import com.cpems.common.core.domain.R;
import com.cpems.common.core.validate.AddGroup;
import com.cpems.common.core.validate.EditGroup;
import com.cpems.common.enums.BusinessType;
import com.cpems.common.utils.poi.ExcelUtil;
import com.cpems.system.domain.vo.SysEnergyProjectVo;
import com.cpems.system.domain.bo.SysEnergyProjectBo;
import com.cpems.system.service.ISysEnergyProjectService;
import com.cpems.common.core.page.TableDataInfo;

/**
 * 各项目每日能效
 *
 * @author lyonfive
 * @date 2025-03-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/energyProject")
public class SysEnergyProjectController extends BaseController {

    private final ISysEnergyProjectService iSysEnergyProjectService;

    /**
     * 查询各项目每日能效列表
     */
    @SaCheckPermission("system:energyProject:list")
    @GetMapping("/list")
    public TableDataInfo<SysEnergyProject> list(SysEnergyProject energy, PageQuery pageQuery) {
       // return iSysEnergyProjectService.queryPageList(bo, pageQuery);
        return iSysEnergyProjectService.selectPageEnergyList(energy,pageQuery);
    }

    /**
     * 导出各项目每日能效列表
     */
    @SaCheckPermission("system:energyProject:export")
    @Log(title = "各项目每日能效", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysEnergyProjectBo bo, HttpServletResponse response) {
        List<SysEnergyProjectVo> list = iSysEnergyProjectService.queryList(bo);
        ExcelUtil.exportExcel(list, "各项目每日能效", SysEnergyProjectVo.class, response);
    }

    /**
     * 获取各项目每日能效详细信息
     *
     * @param energyId 主键
     */
    @SaCheckPermission("system:energyProject:query")
    @GetMapping("/{energyId}")
    public R<SysEnergyProjectVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long energyId) {
        return R.ok(iSysEnergyProjectService.queryById(energyId));
    }

    /**
     * 新增各项目每日能效
     */
    @SaCheckPermission("system:energyProject:add")
    @Log(title = "各项目每日能效", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysEnergyProjectBo bo) {
        return toAjax(iSysEnergyProjectService.insertByBo(bo));
    }

    /**
     * 修改各项目每日能效
     */
    @SaCheckPermission("system:energyProject:edit")
    @Log(title = "各项目每日能效", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysEnergyProjectBo bo) {
        return toAjax(iSysEnergyProjectService.updateByBo(bo));
    }

    /**
     * 删除各项目每日能效
     *
     * @param energyIds 主键串
     */
    @SaCheckPermission("system:energyProject:remove")
    @Log(title = "各项目每日能效", businessType = BusinessType.DELETE)
    @DeleteMapping("/{energyIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] energyIds) {
        return toAjax(iSysEnergyProjectService.deleteWithValidByIds(Arrays.asList(energyIds), true));
    }
}
